﻿package testing {
	import asunit.framework.TestCase;

	public class RegionSetTest extends TestCase {
		private var _instance:RegionSet;

		/**
 		 * Constructor
 		 *
 		 * @param testMethod Name of the method to test
 		 */
 		public function RegionSetTest(testMethod:String) {
 			super(testMethod);
 		}

		/**
	 	 * Prepare for test, create instance of class that we are testing.
	 	 * Invoked by TestCase.runMethod function.
	 	 */
		protected override function setUp():void {
	 		_instance = new RegionSet();
	 	}

		/**
	 	 * Clean up after test, delete instance of class that we were testing.
	 	 */
	 	protected override function tearDown():void {
	 		_instance = null;
	 	}

		/**
	 	 * Test of whether or not class properly instantiated
	 	 */
	 	public function test2by2():void {
			_instance.setup(2,2);
	 		assertTrue("instantiated", _instance.count() == 4);
	 	}
		/**
	 	 * Test of adding moles to regions
	 	 */
	 	public function testAddItem():void {
			_instance.setup(2,2);
			var item = "Mole at region 3";
			_instance.addItem(3, item);
			var items = _instance.getItems(3);
			assertEquals("contains mole region 3", items[0], item);
		}

	 	public function testAddItem2():void {
			_instance.setup(2,2);
			var item = "Mole at region 3";
			_instance.addItem(3, item);
			var items = _instance.getItems(3);
			assertTrue("one mole in region 3", _instance.countItems(3) == 1);
		}

	 	public function testAddItemTooLow():void {
			_instance.setup(2,2);
			var item = "Mole at region 0 is impossible";
			try {
				_instance.addItem(0, item);
				fail("shouldn't have succeeded");
			} catch (error:Error) {
			}
		}

	 	public function testAddItemTooHigh():void {
			_instance.setup(2,2);
			var item = "Mole at region 5 is impossible";
			try {
				_instance.addItem(5, item);
				fail("shouldn't have succeeded");
			} catch (error:Error) {
			}
		}
		
		/**
	 	 * Test of removing moles from regions
	 	 */
	 	public function testRemoveItem():void {
			_instance.setup(2,2);
			var item = "Mole at region 3";
			_instance.addItem(3, item);
			_instance.removeItem(3, item);
			assertTrue("no items in region 3", _instance.countItems(3) == 0);			
		}
	}
}